﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CSP.Common.Web;
using CSP.Bll;
using CSP.Bll.IObjectBlls;
using CSP.Model.CSPEnum;

namespace CSP.Web.MyHome.Activity.CollectBusinessInfo
{
    public partial class Detail : CSPMyHome
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindUI();
        }

        private void BindUI()
        {
            int id = Convert.ToInt32(Request["id"].ToString());
            CSP.Model.CSP.CollectBusinessInfo info = GetByIdAndUserName(id, UserProvider.UserName);
            this.LBName.Text= info.Name;
            this.LBPhone.Text = info.Phone;
            this.LBMobile.Text = info.Mobile;
            this.LBRemark.Text = info.Remark;
            this.LBStatus.Text = GetStatusNameByStatus(info.Status.Value);
        }



        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private CSP.Model.CSP.CollectBusinessInfo GetByIdAndUserName(int id, string userName)
        {
            CSPBllFactory bllFactory = CSPBllFactory.GetInstance();
            CSP.Model.CSP.CollectBusinessInfo collectBusinessInfo = null;

            using (ICollectBusinessInfoBll collectBusinessBll = bllFactory.GetCollectBusinessInfoBll())
            {
                collectBusinessInfo = collectBusinessBll.GetDataById(id);
            }

            if (collectBusinessInfo == null || collectBusinessInfo.UserName != userName || (CollectBusinessInfoStatus)collectBusinessInfo.Status == CollectBusinessInfoStatus.Accomplish)
            {
                string msg = "权限不足";
                LoggerProvider.Error(msg);
                this.FailRedirect("权限不足", "/MyHome/ServiceInfo/List.aspx");
            }

            return collectBusinessInfo;
        }

        private string GetStatusNameByStatus(int status)
        {
            if ((CollectBusinessInfoStatus)status == CollectBusinessInfoStatus.Processing)
            {
                return "审核中";
            }
            else if ((CollectBusinessInfoStatus)status == CollectBusinessInfoStatus.Failed)
            {
                return "审核失败";
            }
            else
            {
                return "审核通过";
            }
        }

    }
}